package sample;

import com.android.ddmlib.AndroidDebugBridge;
import com.android.ddmlib.IDevice;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.Initializable;
import javafx.scene.control.ListView;

import java.net.URL;
import java.util.ResourceBundle;

/**
 * Created by Administrator on 2016/6/27.
 */
public class DeviceController implements Initializable, AndroidDebugBridge.IDeviceChangeListener {
    public ListView<String> deviceList;
    private ObservableList<String> devices = FXCollections.observableArrayList();

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        deviceList.setItems(devices);
        AdbDeviceManager manager = new AdbDeviceManager(this);
        manager.start();
    }

    @Override
    public void deviceConnected(IDevice device) {
        Platform.runLater(() -> devices.add(device.getSerialNumber()));
        if (devices.size() >= 5) {

        }
    }

    @Override
    public void deviceDisconnected(IDevice device) {
        Platform.runLater(() -> devices.remove(device.getSerialNumber()));
    }

    @Override
    public void deviceChanged(IDevice device, int changeMask) {

    }
}
